﻿using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

	public Bow myBow;
	public ShortSword mySword;
	public TwohandedSword myTwoHandedSword;
	public Shield myShield;
	
	public float m_Speed;
	public Weapon m_CurrentWeapon;
	
	private float m_JumpSpeed = 100;
	private Vector2 velocity;
	
	void Start () 
	{
		velocity = Vector2.zero;
		Invoke("MyInvoke", 1f);
	}
	void InvokeTest()
	{
		//Invoke("MyInvoke", 1f);
		
	}
	//this function is called 1 sec later
	void MyInvoke()
	{
		Debug.Log ("Invokeworks");
	}
	// Update is called once per frame
	void FixedUpdate () 
	{
		PlayerAttack();
		PlayerMovements();
		PlayerJumps();
		EquipWeapon();

		//rigidbody2D.velocity = velocity;
	}
	
	void PlayerMovements()
	{
		if(Input.GetKey(KeyCode.RightArrow)) 
		{	
			rigidbody2D.velocity += Vector2.right;
			gameObject.transform.rotation = Quaternion.Euler(0f,0f,0f); 
		}	
		/*if(Input.GetKey(KeyCode.UpArrow)) 
			velocity += Vector2.up;*/
		
	 	if(Input.GetKey(KeyCode.LeftArrow)) 
		{	
			rigidbody2D.velocity += -Vector2.right;
			gameObject.transform.rotation = Quaternion.Euler(0f,180f,0f); 
		}	
			
		/*if(Input.GetKey(KeyCode.DownArrow)) 
			velocity += -Vector2.up;*/			
	
	}
	void PlayerJumps()
	{
		if(Input.GetKeyDown(KeyCode.J))
		{
			//rigidbody2D.AddForce(Vector2.up * m_JumpSpeed * Time.deltaTime);
			rigidbody2D.velocity += new Vector2( 0 , 10 );
			Debug.Log ("player jumps");
		}	
	}
	void EquipWeapon()	
	{
		if(Input.GetKeyDown(KeyCode.S))
		{
			m_CurrentWeapon = mySword;
		}
		if(Input.GetKeyDown(KeyCode.B))
		{
			m_CurrentWeapon = myBow;
		}
		
	}
	void PlayerAttack()
	{
		if (Input.GetKeyDown(KeyCode.A))
		{
			m_CurrentWeapon.Attack();
			
		}
	}
}
